home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / packages.el.z / packages.el
Encoding:
Text File  |  1998-05-21  |  9.8 KB  |  280 lines

  1. ;;; packages.el --- Low level support for XEmacs packages
  2.  
  3. ;; Copyright (C) 1997 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Steven L Baur <steve@altair.xemacs.org>
  6. ;; Keywords: internal, lisp
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;; XEmacs is free software; you can redistribute it and/or modify it
  11. ;; under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; XEmacs is distributed in the hope that it will be useful, but
  16. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;; General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  22. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: Not in FSF
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; This file provides low level facilities for XEmacs startup.  Special
  30. ;; requirements apply to some of these functions because they can be called
  31. ;; during build from temacs and much of the usual lisp environment may
  32. ;; be missing.
  33.  
  34. ;;; Code:
  35.  
  36. (defvar autoload-file-name "auto-autoloads.el"
  37.   "Filename that autoloads are expected to be found in.")
  38.  
  39. (defvar packages-hardcoded-lisp
  40.   '(
  41.     ;; "startup"
  42.     )
  43.   "Lisp packages that are always dumped with XEmacs")
  44.  
  45. (defvar packages-useful-lisp
  46.   '("bytecomp"
  47.     "byte-optimize"
  48.     "advice"
  49.     "shadow")
  50.   "Lisp packages that need early byte compilation.")
  51.  
  52. (defvar packages-unbytecompiled-lisp
  53.   '("paths.el"
  54.     "version.el")
  55.   "Lisp packages that should not be byte compiled.")
  56.  
  57. ;; Copied from subr.el
  58. (defmacro lambda (&rest cdr)
  59.   "Return a lambda expression.
  60. A call of the form (lambda ARGS DOCSTRING INTERACTIVE BODY) is
  61. self-quoting; the result of evaluating the lambda expression is the
  62. expression itself.  The lambda expression may then be treated as a
  63. function, i.e., stored as the function value of a symbol, passed to
  64. funcall or mapcar, etc.
  65.  
  66. ARGS should take the same form as an argument list for a `defun'.
  67. DOCSTRING is an optional documentation string.
  68.  If present, it should describe how to call the function.
  69.  But documentation strings are usually not useful in nameless functions.
  70. INTERACTIVE should be a call to the function `interactive', which see.
  71. It may also be omitted.
  72. BODY should be a list of lisp expressions."
  73.   ;; Note that this definition should not use backquotes; subr.el should not
  74.   ;; depend on backquote.el.
  75.   ;; #### - I don't see why.  So long as backquote.el doesn't use anything
  76.   ;; from subr.el, there's no problem with using backquotes here.  --Stig 
  77.   ;;(list 'function (cons 'lambda cdr)))
  78.   ;; -slb, This has to run in a naked temacs.  Enough is enough.
  79.   ;; `(function (lambda ,@cdr)))
  80.   (list 'function (cons 'lambda cdr)))
  81.  
  82.  
  83. ;; Copied from help.el, could possibly move it to here permanently.
  84. ;; Unlike the FSF version, our `locate-library' uses the `locate-file'
  85. ;; primitive, which should make it lightning-fast.
  86.  
  87. (defun locate-library (library &optional nosuffix path interactive-call)
  88.   "Show the precise file name of Emacs library LIBRARY.
  89. This command searches the directories in `load-path' like `M-x load-library'
  90. to find the file that `M-x load-library RET LIBRARY RET' would load.
  91. Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
  92. to the specified name LIBRARY.
  93.  
  94. If the optional third arg PATH is specified, that list of directories
  95. is used instead of `load-path'."
  96.   (interactive (list (read-string "Locate library: ")
  97.                      nil nil
  98.                      t))
  99.   (let ((result
  100.      (locate-file
  101.       library
  102.       (or path load-path)
  103.       (cond ((or (rassq 'jka-compr-handler file-name-handler-alist)
  104.              (and (boundp 'find-file-hooks)
  105.               (member 'crypt-find-file-hook find-file-hooks)))
  106.          ;; Compression involved.
  107.          (if nosuffix
  108.              ":.gz:.Z"
  109.            ".elc:.elc.gz:elc.Z:.el:.el.gz:.el.Z::.gz:.Z"))
  110.         (t
  111.          ;; No compression.
  112.          (if nosuffix
  113.              ""
  114.            ".elc:.el:")))
  115.       4)))
  116.     (and interactive-call
  117.      (if result
  118.          (message "Library is file %s" result)
  119.        (message "No library %s in search path" library)))
  120.     result))
  121.  
  122. (defun packages-add-suffix (str)
  123.   (if (null (string-match "\\.el\\'" str))
  124.       (concat str ".elc")
  125.     str))
  126.  
  127. (defun list-autoloads-path ()
  128.   "List autoloads from precomputed load-path."
  129.   (let ((path load-path)
  130.     autoloads)
  131.     (while path
  132.       (if (file-exists-p (concat (car path)
  133.                  autoload-file-name))
  134.       (setq autoloads (cons (concat (car path)
  135.                     autoload-file-name)
  136.                 autoloads)))
  137.       (setq path (cdr path)))
  138.     autoloads))
  139.  
  140. (defun list-autoloads ()
  141.   "List autoload files in (what will be) the normal lisp search path.
  142. This function is used during build to find where the global symbol files so
  143. they can be perused for their useful information."
  144.   ;; Source directory may not be initialized yet.
  145.   ;; (print (prin1-to-string load-path))
  146.   (if (null source-directory)
  147.       (setq source-directory (concat (car load-path) "/..")))
  148.   (let ((files (directory-files source-directory t ".*"))
  149.     file autolist)
  150.     (while (setq file (car-safe files))
  151.       (if (and (file-directory-p file)
  152.            (file-exists-p (concat file "/" autoload-file-name)))
  153.       (setq autolist (cons (concat file "/" autoload-file-name)
  154.                    autolist)))
  155.       (setq files (cdr files)))
  156.     autolist))
  157.  
  158. ;; The following function is called from temacs
  159. (defun packages-find-packages-1 (package path-only user-package)
  160.   "Search the supplied directory for associated directories.
  161. The top level is assumed to look like:
  162. info/           Contain texinfo files for lisp installed in this hierarchy
  163. etc/            Contain data files for lisp installled in this hiearchy
  164. lisp/           Contain directories which either have straight lisp code
  165.                 or are self-contained packages of their own.
  166.  
  167. This is an internal function.  Do not call it after startup."
  168.   ;; Info files
  169.   (if (and (null path-only) (file-directory-p (concat package "/info")))
  170.       (let ((dir (concat package "/info/")))
  171.     (when (not (member dir Info-default-directory-list))
  172.       (nconc Info-default-directory-list (list dir)))))
  173.   ;; Data files
  174.   (if (and (null path-only) (file-directory-p (concat package "/etc")))
  175.       (setq data-directory-list
  176.         (cons (concat package "/etc/") data-directory-list)))
  177.   ;; Lisp files
  178.   (if (file-directory-p (concat package "/lisp"))
  179.       (progn
  180. ;    (print (concat "DIR: "
  181. ;               (if user-package "[USER]" "")
  182. ;               package
  183. ;               "/lisp/"))
  184.     (setq load-path (cons (concat package "/lisp/") load-path))
  185.     (if user-package
  186.         (condition-case nil
  187.         (load (concat package "/lisp/"
  188.                   (file-name-sans-extension autoload-file-name)))
  189.           (t nil)))
  190.     (let ((dirs (directory-files (concat package "/lisp/")
  191.                      t "^[^-.]" nil 'dirs-only))
  192.           dir)
  193.       (while dirs
  194.         (setq dir (car dirs))
  195. ;        (print (concat "DIR: " dir "/"))
  196.         (setq load-path (cons (concat dir "/") load-path))
  197.         (if user-package
  198.         (condition-case nil
  199.             (progn
  200. ;              (print
  201. ;               (concat dir "/"
  202. ;                   (file-name-sans-extension autoload-file-name)))
  203.               (load
  204.                (concat dir "/"
  205.                    (file-name-sans-extension autoload-file-name))))
  206.           (t nil)))
  207.         (packages-find-packages-1 dir path-only user-package)
  208.         (setq dirs (cdr dirs)))))))
  209.  
  210. ;; The following function is called from temacs
  211. (defun packages-find-packages (pkg-path path-only &optional suppress-user)
  212.   "Search the supplied path for additional info/etc/lisp directories.
  213. Lisp directories if configured prior to build time will have equivalent
  214. status as bundled packages.
  215. If the argument `path-only' is non-nil, only the `load-path' will be set,
  216. otherwise data directories and info directories will be added.
  217. If the optional argument `suppress-user' is non-nil, package directories
  218. rooted in a user login directory (like ~/.xemacs) will not be searched.
  219. This is used at dump time to suppress the builder's local environment."
  220.   (let ((path (reverse pkg-path))
  221.     dir)
  222.     ;; The inhibit-package-init test does not work with packages.
  223.     ;; it works well enough with 20.3.
  224.     (while path
  225.       (setq dir (car path))
  226.       ;; (prin1 (concat "Find: " (expand-file-name dir) "\n"))
  227.       (if (null (and dir
  228.              (or suppress-user inhibit-package-init)
  229.              (string-match "^~" dir)))
  230.       (progn
  231.         ;; (print dir)
  232.         (packages-find-packages-1 (expand-file-name dir)
  233.                       path-only
  234.                       (string-match "^~" dir))))
  235.       (setq path (cdr path)))))
  236.  
  237. ;; Data-directory is really a list now.  Provide something to search it for
  238. ;; directories.
  239.  
  240. (defun locate-data-directory (name &optional dir-list)
  241.   "Locate a directory in a search path DIR-LIST (a list of directories).
  242. If no DIR-LIST is supplied, it defaults to `data-directory-list'."
  243.   (unless dir-list
  244.     (setq dir-list data-directory-list))
  245.   (let (found found-dir)
  246.     (while (and (null found-dir) dir-list)
  247.       (setq found (concat (car dir-list) name "/")
  248.         found-dir (file-directory-p found))
  249.       (or found-dir
  250.       (setq found nil))
  251.       (setq dir-list (cdr dir-list)))
  252.     found))
  253.  
  254. ;; Data-directory is really a list now.  Provide something to search it for
  255. ;; files.
  256.  
  257. (defun locate-data-file (name &optional dir-list)
  258.   "Locate a file in a search path DIR-LIST (a list of directories).
  259. If no DIR-LIST is supplied, it defaults to `data-directory-list'."
  260.   (unless dir-list
  261.     (setq dir-list data-directory-list))
  262.   (let (found found-file)
  263.     (while (and (null found-file) dir-list)
  264.       (setq found (concat (car dir-list) name)
  265.         found-file (and (file-exists-p found)
  266.                 (not (file-directory-p found))))
  267.       (or found-file
  268.       (setq found nil))
  269.       (setq dir-list (cdr dir-list)))
  270.     found))
  271.  
  272. ;; If we are being loaded as part of being dumped, bootstrap the rest of the
  273. ;; load-path for loaddefs.
  274. (if (fboundp 'load-gc)
  275.     (packages-find-packages package-path t t))
  276.  
  277. (provide 'packages)
  278.  
  279. ;;; packages.el ends here
  280.